/*
 * Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */
/**
 * \addtogroup cc2538
 * @{
 *
 * \defgroup cc2538-examples cc2538dk Example Projects
 * @{
 *
 * \defgroup cc2538dk oled Demo Project
 *
 * \file
 *     Example demonstrating the cc2538dk platform
 */
#include "contiki.h"
#include "cpu.h"
#include "sys/etimer.h"
#include "sys/rtimer.h"
#include "dev/leds.h"
#include "dev/oled-arch.h"
#include "dev/watchdog.h"
#include "dev/sys-ctrl.h"

#include <stdio.h>
#include <stdint.h>
/*---------------------------------------------------------------------------*/
#define LOOP_INTERVAL       CLOCK_SECOND
/*---------------------------------------------------------------------------*/
static struct etimer et;
static unsigned int y,d;
/*---------------------------------------------------------------------------*/

const unsigned char tab[]=
{
/* 点阵格式：阴码； 取模走向：顺向(高位在前)； 取模方式：逐列式； 自定义格式：C51格式*/
/* 001 O  */
0x0F,0xE0,0x10,0x10,0x20,0x08,0x20,0x08,0x20,0x08,0x10,0x10,0x0F,0xE0,0x00,0x00,

/* 002 L  */
0x20,0x08,0x3F,0xF8,0x20,0x08,0x20,0x00,0x20,0x00,0x20,0x00,0x30,0x00,0x00,0x00,

/* 003 E  */
0x20,0x08,0x3F,0xF8,0x20,0x88,0x20,0x88,0x23,0xE8,0x20,0x08,0x18,0x10,0x00,0x00,

/* 004 D  */
0x20,0x08,0x3F,0xF8,0x20,0x08,0x20,0x08,0x20,0x08,0x10,0x10,0x0F,0xE0,0x00,0x00,

/* 005 显  */
0x40,0x00,0x42,0x00,0x44,0x00,0x58,0xFE,0x40,0x92,0x7F,0x92,0x40,0x92,0x40,0x92,
0x40,0x92,0x7F,0x92,0x40,0x92,0x50,0xFE,0x48,0x00,0x46,0x00,0x40,0x00,0x00,0x00,

/* 006 示  */
0x20,0x40,0x10,0x40,0x08,0x42,0x06,0x42,0x00,0x42,0x40,0x42,0x80,0x42,0x7F,0xC2,
0x00,0x42,0x00,0x42,0x00,0x42,0x02,0x42,0x04,0x42,0x08,0x40,0x30,0x40,0x00,0x00,

/* 007 屏  */
0x40,0x00,0x30,0x00,0x0F,0xFE,0x04,0x12,0x84,0x92,0x64,0xB2,0x1F,0xD2,0x04,0x92,
0x04,0x92,0x04,0x92,0xFF,0xD2,0x04,0xB2,0x04,0x9E,0x04,0x00,0x00,0x00,0x00,0x00,

};

const unsigned char tab2[]=
{
/* 001 三  */
0x20,0x00,0x20,0x04,0x20,0x84,0x20,0x84,0x20,0x84,0x20,0x84,0x20,0x84,0x20,0x84,
0x20,0x84,0x20,0x84,0x20,0x84,0x20,0x84,0x20,0x84,0x20,0x04,0x20,0x00,0x00,0x00,

/* 002 木  */
0x10,0x00,0x08,0x10,0x04,0x10,0x02,0x10,0x01,0x10,0x00,0xD0,0x00,0x30,0xFF,0xFF,
0x00,0x30,0x00,0xD0,0x01,0x10,0x02,0x10,0x04,0x10,0x08,0x10,0x10,0x00,0x00,0x00,

/* 003 电  */
0x00,0x00,0x00,0x00,0x1F,0xF8,0x08,0x88,0x08,0x88,0x08,0x88,0x08,0x88,0x7F,0xFF,
0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x9F,0xF8,0x80,0x00,0xF0,0x00,0x00,0x00,

/* 004 子  */
0x00,0x80,0x00,0x82,0x00,0x82,0x00,0x82,0x00,0x82,0x40,0x82,0x80,0x82,0x7F,0xE2,
0x00,0xA2,0x00,0x92,0x00,0x8A,0x00,0x86,0x00,0x82,0x00,0x80,0x00,0x80,0x00,0x00,

/* 005 开  */
0x00,0x80,0x80,0x82,0x40,0x82,0x30,0x82,0x0F,0xFE,0x00,0x82,0x00,0x82,0x00,0x82,
0x00,0x82,0x00,0x82,0xFF,0xFE,0x00,0x82,0x00,0x82,0x00,0x82,0x00,0x80,0x00,0x00,

/* 006 发  */
0x00,0x00,0x20,0x00,0x10,0x18,0x8C,0x16,0x83,0x10,0x80,0xD0,0x41,0xB8,0x46,0x97,
0x28,0x90,0x10,0x90,0x28,0x90,0x44,0x92,0x43,0x94,0x80,0x10,0x80,0x00,0x00,0x00,

/* 007 团  */
0x00,0x00,0xFF,0xFE,0x40,0x02,0x48,0x22,0x44,0x22,0x42,0x22,0x51,0x22,0x60,0xA2,
0x5F,0xFA,0x40,0x22,0x40,0x22,0x40,0x22,0x40,0x02,0xFF,0xFE,0x00,0x00,0x00,0x00,

/* 008 队  */
0x00,0x00,0xFF,0xFE,0x08,0x02,0x10,0x22,0x88,0xDA,0x47,0x06,0x20,0x00,0x18,0x00,
0x07,0x00,0x00,0xFF,0x07,0x00,0x18,0x00,0x20,0x00,0x40,0x00,0x80,0x00,0x00,0x00,

};

PROCESS(oled_process, "oled process");
AUTOSTART_PROCESSES(&oled_process);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(oled_process, ev, data)
{
  PROCESS_BEGIN();

  etimer_set(&et, CLOCK_SECOND/100);
  while(1) {

    PROCESS_YIELD();
  
  OLED_Fill(0x00);

  OLED_Display_On(); 

  d=8;
  for(y=0;y<sizeof(tab)/sizeof(unsigned char);y=y+2)
  {
    OLED_Setpos(1,d);
    OLED_WrDat(tab[y]);
    OLED_Setpos(0,d);
    OLED_WrDat(tab[y+1]);
    d++;
  }

  d=0;
  for(y=0;y<sizeof(tab2)/sizeof(unsigned char);y=y+2)
  {
    OLED_Setpos(3,d);
    OLED_WrDat(tab2[y]);
    OLED_Setpos(2,d);
    OLED_WrDat(tab2[y+1]);
    d++;
  }

  }

  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
/**
 * @}
 * @}
 * @}
 */
